package com.niodata.dp.web.module.task;

import com.niodata.dp.util.TimeUtil;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;


public class TaskExecutionGraph {

  private Date startTime = new Date(0);
  private Date endTime = new Date(0);
  private String status = "FAILED";
  private boolean success = false;
  private Map<String, String> taskParams = Collections.EMPTY_MAP;
  private int execId;
  private String taskId;
  private String taskName;
  private Long ownerId;
  private String ownerType;
  private String scheduleCron;
  private String description;
  private List<TaskExecutionGraph.TaskNode> nodes;
  private List<TaskExecutionGraph.NodeEdge> edges;

  public Map<String, String> getTaskParams() {
    return taskParams;
  }

  public void setTaskParams(Map<String, String> taskParams) {
    this.taskParams = taskParams;
  }

  public String getTaskName() {
    return taskName;
  }

  public void setTaskName(String taskName) {
    this.taskName = taskName;
  }

  public Long getOwnerId() {
    return ownerId;
  }

  public void setOwnerId(Long ownerId) {
    this.ownerId = ownerId;
  }

  public String getOwnerType() {
    return ownerType;
  }

  public void setOwnerType(String ownerType) {
    this.ownerType = ownerType;
  }

  public String getScheduleCron() {
    return scheduleCron;
  }

  public void setScheduleCron(String scheduleCron) {
    this.scheduleCron = scheduleCron;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public List<TaskExecutionGraph.TaskNode> getNodes() {
    return nodes;
  }

  public void setNodes(List<TaskExecutionGraph.TaskNode> nodes) {
    this.nodes = nodes;
  }

  public List<TaskExecutionGraph.NodeEdge> getEdges() {
    return edges;
  }

  public void setEdges(List<TaskExecutionGraph.NodeEdge> edges) {
    this.edges = edges;
  }

  public int getExecId() {
    return execId;
  }

  public void setExecId(int execId) {
    this.execId = execId;
  }

  public String getTaskId() {
    return taskId;
  }

  public void setTaskId(String taskId) {
    this.taskId = taskId;
  }

  public Date getStartTime() {
    return startTime;
  }

  public void setStartTime(Date startTime) {
    this.startTime = startTime;
  }

  public Date getEndTime() {
    return endTime;
  }

  public void setEndTime(Date endTime) {
    this.endTime = endTime;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public static class TaskNode {

    private String className;
    private String pkgId;
    private String nodeId;
    private String jobName;
    private Date startTime = new Date();
    private Date endTime = new Date();
    private String status = "FAILED";
    private boolean success = false;
    private Map<String, String> style;
    private Map<String, Object> params;
    private Map<String, Object> outParams;
    private String jobType;

    public String getPkgId() {
      return pkgId;
    }

    public void setPkgId(String pkgId) {
      this.pkgId = pkgId;
    }

    public String getNodeId() {
      return nodeId;
    }

    public void setNodeId(String nodeId) {
      this.nodeId = nodeId;
    }

    public String getJobName() {
      return jobName;
    }

    public void setJobName(String jobName) {
      this.jobName = jobName;
    }

    public Map<String, Object> getParams() {
      return params;
    }

    public void setParams(Map<String, Object> params) {
      this.params = params;
    }

    public String getClassName() {
      return className;
    }

    public void setClassName(String className) {
      this.className = className;
    }

    public Map<String, String> getStyle() {
      return style;
    }

    public void setStyle(Map<String, String> style) {
      this.style = style;
    }

    public Map<String, Object> getOutParams() {
      return outParams;
    }

    public void setOutParams(Map<String, Object> outPutParams) {
      this.outParams = outPutParams;
    }

    public Date getStartTime() {
      return startTime;
    }

    public void setStartTime(Date startTime) {
      this.startTime = startTime;
    }

    public Date getEndTime() {
      return endTime;
    }

    public void setEndTime(Date endTime) {
      this.endTime = endTime;
    }

    public String getStatus() {
      return status;
    }

    public void setStatus(String status) {
      this.status = status;
    }

    public boolean isSuccess() {
      return success;
    }

    public void setSuccess(boolean success) {
      this.success = success;
    }

    public String getJobType() {
      return jobType;
    }

    public void setJobType(String jobType) {
      this.jobType = jobType;
    }

    public String getElapsed() {
      if (endTime.getTime() < 31536000000L) {
        return "";
      }
      return TimeUtil.toReadableDuration(this.startTime, this.endTime);
    }

  }

  public static class NodeEdge {

    private String source;//source job name
    private String target;//target job name

    public String getSource() {
      return source;
    }

    public void setSource(String source) {
      this.source = source;
    }

    public String getTarget() {
      return target;
    }

    public void setTarget(String target) {
      this.target = target;
    }
  }
}
